package com.qing.thread.join;

/**
 * 线程阻塞（强制插队行为），会造成其他线程阻塞
 */
public class JoinThread implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 500; i++) {
            System.out.println("Vip线程强行插队执行" + i);
        }
    }


    public static void main(String[] args) throws InterruptedException {

        //启动线程
        JoinThread joinThread = new JoinThread();
        Thread thread = new Thread(joinThread);
        thread.start();

        for (int i = 0; i < 200; i++) {
            if (i == 99) {
                //线程强制执行，main线程需要等此线程运行完再继续执行，会阻塞
                thread.join();
            }
            System.out.println("Main线程" + i);
        }
    }
}
